<?php

// +----------------------------------------------------------------------
// | Service
// +----------------------------------------------------------------------
// | 版权所有 
// +----------------------------------------------------------------------
// |
// +----------------------------------------------------------------------
// |
// +----------------------------------------------------------------------

namespace app\admin\controller;

use app\common\model\UserReal;
use think\Controller;
use controller\BasicAdmin;
use service\DataService;
use service\LogService;
use think\Db;

/**
 * 用户列表
 * Class Member
 * @package app\admin\controller
 * @date 2018/08/25 13:51
 */
class Member extends Admin
{

    /**
     * 指定当前数据表
     * @var string
     */
    public $table = 'User';

    //实名认证
    public function real ()
    {
        $userReal = new UserReal();
        $list = $userReal->field('user_real.* ,user.nick_name')
            ->leftJoin('user','user_real.user_id = user.id')
            ->paginate(15, false, [
                'query' => isset($map) ? $map : []
            ]);
        return $this->render('real', [
            'list' => $list,
            'queryStr' => isset($map) ? http_build_query($map) : '',
        ]);
    }
    //通过实名验证
    public function pass()
    {
        $id = $this->request->get('id');
        $status = $this->request->get('status');
        if(!$id) return json(['code' => 0, 'message' => '非法操作']);
        $userReal = new UserReal();
        $userId = $userReal->field('user_id')->where('id',$id)->find();
        $rol = Db('user')->where('id',$userId['user_id'])->update(['real_pass'=>2]);
        $res =$userReal->editStatus($id,$status);
        if (is_int($res)&&is_int($rol)) return json(['code' => 0, 'message' => '审核成功']);
        return json(['code' => 0, 'message' => '非法操作']);
    }
    //删除审核记录
    public function del()
    {
        $id = $this->request->get('id');
        if(!$id) return json(['code' => 0, 'message' => '非法操作']);
        $userReal = new UserReal();
        $res =$userReal->delStatus($id);
        if (is_int($res)) return json(['code' => 0, 'message' => '删除成功']);
        return json(['code' => 0, 'message' => '非法操作']);
    }
}
